<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <cpn></cpn>
        <cpn ref="reference"></cpn>
        <cpn></cpn>
        <button @click="btnclick">案例</button>
    </div>
    <template id="cpn">
        <div>
            我是子组件
        </div>
    </template>
</body>
<script src='../js/vue.js'></script>
<script>
    let app = new Vue({
        el: '#app',
        data: {
             msg:'hello vue.js'
        },
        methods: {
            btnclick(){
                // 第一种方法获取所有的子组件
                // console.log(this.$children);
                // for (const c of this.$children) {
                //     console.log(c.name);
                //     c.showmsg()
                // }
                // 第二种可以过去单个的
                    console.log(this.$refs.reference.name);
            }
        },
        components: {
            cpn: {
                template: '#cpn',
                data() {
                    return {
                        name: '我是子组件name'
                    }
                },
                methods: {
                    showmsg(){
                        console.log('showmsg');
                    }
                },

            }
        }
    })
</script>
</html>